home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 6.3 KB | 217 lines | [TEXT/ttxt] |
- -- Filename:
- -- myStrans.sx
-
- -- Purpose:
- -- This file defines a score translator that
- -- prints information about a score in a Director file
- -- to an output file
-
-
- -- Specialized Classes:
-
- -- The main specialized class is ScoreToInfoTranslator
- -- which defines the translateFrame method to translate
- -- frames in a Director score when importing into ScriptX.
-
-
- -- Instructions to User:
- -- Don't load this file directly.
- -- Instead, load converter.sx, which loads this file.
- -- converter.sx creates an instance of ScoreToInfoTranslator
- -- and uses it to import a score from a Director file
-
- -- Author:
- -- Jocelyn Becker
-
-
-
-
-
- in Module myModule
-
- -- Create the new class of Score Translator
- class ScoreToInfoTranslator (DTKScoreTranslator)
- end
-
-
- method prepareToTranslateScore self {class ScoreToInfoTranslator} ->
- (
- print "\nI am preparing to translate the score. Silence please.\n"
- )
-
-
-
- method translateFrame self {class ScoreToInfoTranslator} \
- prevFrame currentFrame changedArray ->
- (
- local framenum := currentFrame.absoluteFrameNumber
-
- -- Print the frame number
- format self.outputstream "\n\n\nProcessing frame number %* \n" \
- framenum @unadorned
-
- -- Translate data about the frame
- translateTempoDataToText self prevFrame currentFrame
- translateSoundDataToText self prevFrame currentFrame
- translateSpriteDataToText self prevFrame currentFrame changedArray
- )
-
- --------------------------------------------
- -- USER-DEFINED METHODS TO DO TRANSLATING
- --------------------------------------------
-
-
- ---------------------
- -- Translate Tempo --
- ---------------------
-
- method translateTempoDataToText self {class ScoreToInfoTranslator}\
- prevFrame currentFrame ->
- (
- local currentTempo := currentFrame.tempochannel
-
- -- Print a message to the output stream that says whether the
- -- the tempo has changed since the previous frame, and
- -- what the current tempo is.
- if (currentFrame.tempoChannel.tempo <> prevFrame.tempoChannel.tempo)
- then
- format self.outputstream "\nThe tempo has changed to %* \n" \
- currentTempo.tempo @unadorned
- else
- format self.outputstream "\nThe tempo is still %* \n" \
- currentTempo.tempo @unadorned
-
- -- Lets see if we need to wait for any sounds.
- -- The value of the DTKTempoChannel's waitForSound instance variable is:
- -- 0 (don't wait for any sound),
- -- 1 (wait for the sound in channel 1) or
- -- 2 (wait for the sound in channel 2)
- if (currentFrame.tempoChannel.waitForSound <> 0) do
- format self.outputstream "We need to wait for the sound in channel %* to finish \n" \
- currentFrame.tempoChannel.waitForSound @unadorned
-
- )
-
-
- ---------------------
- -- Translate Sound --
- ---------------------
-
- method translateSoundDataToText self {class ScoreToInfoTranslator} \
- prevFrame currentFrame ->
- (
- -- A DTKScoreFrame object has a soundChannels iv that contains
- -- an array of two DTKSoundChannel objects, one for each sound channel
-
- -- For each sound channel, find which position the sound playing
- -- in that channel occupies in the cast list.
- -- Print sutiable messsages to the output stream.
- for i := 1 to 2 do (
- local oldIndex := prevFrame.soundChannels[i].castIndex
- local newIndex := currentFrame.soundChannels[i].castIndex
-
- -- If no sound is playing in this channel, castIndex will be 0
- if (newIndex <> 0)
- then
- format self.outputstream "Sound channel %1 is playing sound %2.\n" \
- #(i, self.castlist[newIndex].mediastream) \
- #(@unadorned, @unadorned)
- else
- format self.outputstream "Sound channel %* is currently silent.\n" \
- i @unadorned
-
- if newIndex <> oldIndex
- then
- format self.outputstream "This is a change from the previous frame. \n" \
- 1 @unadorned
- else
- format self.outputstream "This is the same as for the previous frame. \n" \
- 1 @unadorned
-
- -- close loop
- )
- )
-
-
- -----------------------
- -- Translate Sprites --
- -----------------------
-
- method translateSpriteDataToText self {class ScoreToInfoTranslator} \
- prevFrame currentFrame changedArray ->
-
- (
- -- Get the cast list.
- theCastList := self.castlist
-
- -- For each sprite channel:
- for i := 1 to 48 do
- (
- -- Find which sprite channel we are currently focusing on.
- local theSpriteChannel := currentFrame.spriteChannels[i]
- local thePrevSpriteChannel := prevFrame.spriteChannels[i]
-
- -- Find which position the sprite that appears in
- -- that channel occupies in the cast list.
- local spritePosition := theSpriteChannel.castIndex
- local prevSpritePosition := thePrevSpriteChannel.castIndex
-
- -- Find the actual cast member object for the sprite in the channel
- thisCast := theCastList[spritePosition]
- prevCast := theCastList[prevSpritePosition]
-
- -- Print suitable messages to the output stream.
- if thisCast <> empty do
- (
- format self.outputstream "\n The castmember in channel %1 is %2. \n\
- Its name is %10. \n.
- It is at position %3 in the cast list. \n\
- This cast member is a %4. \n \
- Its x coordinate is %5. \n \
- Its y coordinate is %6.\n \
- Its inkmode is %7. \n \
- It is %8 high and %9 wide. \n\n" \
- #(i, thisCast, spritePosition, (getClass thisCast), \
- theSpriteChannel.x, theSpriteChannel.y, \
- thespriteChannel.ink, \
- theSpriteChannel.height, theSpriteChannel.width, thisCast.name) \
- #(@unadorned, @unadorned, @unadorned, @unadorned, @unadorned,
- @unadorned, @unadorned, @unadorned, @unadorned)
-
-
-
- if changedArray[i] == false
- then
- print "No change in this sprite channel." self.outputstream
- else
- (
- -- Compare the ink mode of the current and previous frames
- if (thePrevSpriteChannel.ink <> theSpriteChannel.ink)
- do
- print "The ink mode has changed since the previous channel.\n" \
- self.outputstream
-
- -- Comparing the state of the sprite in the
- -- current and previous frames
-
- if (thisCast <> prevCast)
- do
- print "The sprite has changed." self.outputstream
-
- if (thePrevSpriteChannel.x <> theSpriteChannel.x) or
- (thePrevSpriteChannel.y <> theSpriteChannel.y)
- do
- print "The sprite has changed position." self.outputstream
-
-
- if (thePrevSpriteChannel.width <> theSpriteChannel.width) or
- (thePrevSpriteChannel.height <> theSpriteChannel.height)
- do
- print "The sprite has changed size." self.outputstream
- ) -- closes if changedArray[i] == false
-
- ) -- closes if thisCast <> empty else
-
- ) -- closes for i := 1 to 48 do
- ) -- closes method
-